package cn.cxd.leetcode;

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;

public class Leetcode2530 {

    public long maxKelements(int[] nums, int k) {
        long res = 0L;
        Queue<Integer> queue = new PriorityQueue<>(Comparator.reverseOrder());

        for (int num : nums) {
            queue.offer(num);
        }
        for (int i = 0; i < k; i++) {
            int max = queue.poll();
            res += max;
            queue.offer((int) Math.ceil(max / 3.0));
        }
        return res;
    }

}
